<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body,ul,li,a{
            margin: 0;
            padding: 0;
        }
        ul{
            list-style-type: none;
            width: 750px;
            height: 40px;
            border: 1px solid #ccc;
            margin: 100px auto;
        }
        ul li{
            float: left;
            width: 150px;
            height: 40px;
            text-align: center;
            line-height: 40px;
        }
        ul li a{
            text-decoration: none;
            color: #333;
            display: block;
        }
        ul li a.active{
            background: purple;
            color: #fff;
        }
    </style>
</head>
<body>
    <ul>
        <li><a class="active" href="#">首页</a></li>
        <li><a href="#">首页</a></li>
        <li><a href="#">首页</a></li>
        <li><a href="#">首页</a></li>
        <li><a href="#">首页</a></li>
    </ul>
</body>
</html>
<script>
    var aA = document.getElementsByTagName("a");
    for(var i=0;i<aA.length;i++){
        aA[i].onclick = function () {
            for(var i=0;i<aA.length;i++){
                aA[i].className = "";
            }
            this.className = "active";
        }
    }
</script>